package cn.honglian.basic.controller;

import cn.honglian.basic.anno.PreAuthorize;
import cn.honglian.basic.dto.FountPhoneLoginDto;
import cn.honglian.basic.dto.LoginDto;
import cn.honglian.basic.dto.WechatDto;
import cn.honglian.basic.dto.WxBuderDto;
import cn.honglian.basic.service.LoginService;
import cn.honglian.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
@PreAuthorize()
public class LoginController {
    @Autowired
    private LoginService loginService;
    /*
        后台管理员登录
     */
    @PostMapping("/account")
    @PreAuthorize(name = "后台登录",sn = "login:account")
    public AjaxResult account(@RequestBody @Valid LoginDto dto ) {
        Map<String,Object> map = loginService.account(dto);
        return AjaxResult.me().success(map);
    }
    /*
       前台用户登录
    */
    @PostMapping("/account/phone")
    public AjaxResult accountPhone(@RequestBody @Valid FountPhoneLoginDto dto ) {
        Map<String, Object> map = loginService.accountPhone(dto);
        return AjaxResult.me().success(map);
    }


    /*
           微信扫码登录
        */
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WechatDto dto ) {

        return loginService.wechat(dto);
    } /*
           微信扫码授权登录
        */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody @Valid WxBuderDto dto ) {
        Map<String, Object> map = loginService.wechatBinder(dto);
        return AjaxResult.me().success(map);
    }
}
